var app = getApp(),
  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    // tab切换  
    currentTab: 0,
    re_pay:false,
    objarr: [],
    page: 1,
    pagesize: 5,
    totalpage: 0,//最大页数
    height: 0,
    user_status:'n'
  },
  onLoad: function () {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight - 40 })
      }
    })
    this.getData()
  },
  getData(){
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
      use_status: this.data.user_status,
      page: this.data.page,
      pagesize: this.data.pagesize
    }
    $.httpPost("member_coupon", params, (data, err) => {
      this.setData({
        objarr: data.data.list,
        totalpage: data.data.total_page
      })
    })
  },
  clicktab(e){
    console.log(e.target)
    let tab = e.target.dataset.tab
    if (this.data.currentTab != tab){
      this.setData({
        currentTab: tab
      })
    }
    if(tab!=0){
      this.setData({
        re_pay:true,
        user_status:'y',
        objarr:[],
        page:1
      })
      this.getData()
    }else{
      this.setData({
        re_pay: false,
        user_status: 'n',
        objarr:[],
        page:1
      })
      this.getData()
    }
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        use_status: this.data.user_status,
        page: this.data.page,
        pagesize: this.data.pagesize
      }
      $.httpPost("member_coupon", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },

  toGoods() {
    let status = 'buy'
    wx.navigateTo({
      url: '/pages/goodscat/goodscat?status=' + status,
    })
  },
  
    
})  